package com.micro.modual.extension;

import com.micro.common.MicroConstant;
import com.micro.common.biz.GeneratorCodeUtil;
import com.micro.common.util.SnowFlakeUtil;
import com.micro.modual.entity.GoodsSku;
import com.micro.modual.entity.Prefecture;
import com.micro.modual.model.bo.prefecture.PrefectureBO;
import com.micro.modual.model.dto.goodssku.GoodsSkuListDTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <h1>专区表 延展类</h1>
 *
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:23:26
 */
public class PrefectureExtension {

    /**
     * <h2>转换: 专区表 新增</h2>
     *
     * @param prefectureBO {@link PrefectureBO} 专区表 新增/修改 请求对象
     * @return {@link Prefecture} 专区表
     */
    public static Prefecture converAddPrefecture(PrefectureBO prefectureBO) {
        Prefecture prefecture = new Prefecture();
        prefecture.setId(SnowFlakeUtil.getId());
        prefecture.setCreateTime(new Date());
        prefecture.setBrowsingVolume(MicroConstant.SystemDefaultValue.DEFAULT_START_COUNT);
        prefecture.setGoodsNumber(MicroConstant.SystemDefaultValue.DEFAULT_START_COUNT);
        prefecture.setPrefectureCode(GeneratorCodeUtil.generatorSystemCode());
        prefecture.setIsShow(prefectureBO.getIsShow());
        prefecture.setPrefectureName(prefectureBO.getPrefectureName());
        prefecture.setPrefectureSketch(prefectureBO.getPrefectureSketch());
        prefecture.setPrefectureSort(prefectureBO.getPrefectureSort());
        prefecture.setPrefectureLogo(prefectureBO.getPrefectureLogo());
        prefecture.setPrefectureBackdrop(prefectureBO.getPrefectureBackdrop());
        return prefecture;
    }

    /**
     * <h2>转换: 专区表 修改</h2>
     *
     * @param prefectureBO {@link PrefectureBO} 专区表 新增/修改 请求对象
     * @return {@link Prefecture} 专区表
     */
    public static Prefecture converEditPrefecture(PrefectureBO prefectureBO) {
        Prefecture prefecture = new Prefecture();
        prefecture.setId(prefectureBO.getId());
        prefecture.setIsShow(prefectureBO.getIsShow());
        prefecture.setPrefectureName(prefectureBO.getPrefectureName());
        prefecture.setPrefectureSketch(prefectureBO.getPrefectureSketch());
        prefecture.setPrefectureSort(prefectureBO.getPrefectureSort());
        prefecture.setPrefectureLogo(prefectureBO.getPrefectureLogo());
        prefecture.setPrefectureBackdrop(prefectureBO.getPrefectureBackdrop());
        prefecture.setUpdateTime(new Date());
        return prefecture;
    }


    public static List<GoodsSkuListDTO> convertGoodsSkuListDTO(List<String> skuCodeList, List<GoodsSku> goodsSkuList) {
        List<GoodsSkuListDTO> goodsSkuListDTOList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(goodsSkuList)){
            for(GoodsSku goodsSku:goodsSkuList){
                if(skuCodeList.contains(goodsSku.getSkuCode())){
                    continue;
                }
                GoodsSkuListDTO goodsSkuListDTO = new GoodsSkuListDTO();
                BeanUtils.copyProperties(goodsSku,goodsSkuListDTO);
                goodsSkuListDTOList.add(goodsSkuListDTO);
            }
        }
        return goodsSkuListDTOList;
    }
}
